package dao;

import java.sql.SQLException;
import java.util.List;


import entity.Order;
import entity.Order_item;
import utils.JdbcUtils;

public class OrderDao {
	// {1}增加
	public void addOrder(Order order) throws SQLException {
		String sql = "insert into o(oid,uid,trade_status,pay_status,pay_amount,order_trade_no,pay_time,create_time,remark,phone,address,consignee)"
						+ "values(?,?,?,?,?,?,?,?,?,?,?,?)";// ?表示占位符，填充插入占位符时表中有几列就写几
		int row = JdbcUtils.update(sql, order.getOid(),order.getUid(),order.getTrade_status(),order.getPay_status(),order.getPay_amount(),order.getOrder_trade_no(),order.getPay_time(),order.getCreate_time(),order.getRemark(),order.getPhone(),order.getAddress(),order.getConsignee());
		System.out.println("已增加" + row + "行数据");
	}

	// {2}删除
	public void deleteOrder(Order order) throws SQLException {
		String sql = "delete from o where oid=?";
		int row = JdbcUtils.update(sql, order.getOid());
		System.out.println("已删除" + row + "行数据");
	}

	// {3}修改
	public void updateOrder(Order order) throws SQLException {
		String sql = "update o set order=? where oid=?";
		int row = JdbcUtils.update(sql, order.getOid(), order.getOid());
		System.out.println("已修改" + row + "行数据");
	}

	// {4}根据订单号ID查询
	public Order queryByOId(String order) throws SQLException {
		String sql = "select * from o c where c.oid=?";

		Order c = JdbcUtils.query(sql, Order.class, order);
		return c;
	}

	// {5}查询所有记录
	public List<Order> queryAll() throws SQLException {
		List<Order> list = null;
		String sql = "select * from o where id<=?";
		list = JdbcUtils.queryList(sql, Order.class,20);
		return list;
	}
	// {6}根据用户ID查询所有记录
	public  List<Order> queryUidAll(int uid) throws SQLException {
		List<Order> list = null;
		String sql = "select * from o g where g.uid=?";
		list = JdbcUtils.queryList(sql, Order.class,uid);
		return list;
	}

}
